//
//  YDBuyStrategyTopView.m
//  PeiZiWangBei
//
//  Created by LK-IOS on 2017/11/15.
//  Copyright © 2017年 LK-IOS. All rights reserved.
//

#import "YDBuyStrategyTopView.h"
//策略界面上方显示单只股票信息的view
@interface YDBuyStrategyTopView()

//股票名称
@property (nonatomic , weak) UILabel *stockName;
//股票代码
@property (nonatomic , weak) UILabel *stockCode;

//最新价
@property (nonatomic , weak) UILabel *nowPrice;
@property (nonatomic , weak) UILabel *price;
@end


@implementation YDBuyStrategyTopView

-(void)setDict:(NSDictionary *)dict
{
    //单只股票信息
    _dict = dict;
    
    if (!dict) {
        return;
    }else{
        //名称代码
        self.stockName.text = dict[@"name"];
        self.stockCode.text = dict[@"instrumentId"];
        NSString *priceString = [NSString stringWithFormat:@"%@", dict[@"lastPrice"]];
        //价格及价格涨跌
        self.price.text = [priceString pz_stringNumberByMultiplyingBy:@"1"];
        //颜色
        self.price.textColor = [dict[@"upDropPrice"] floatValue] > 0 ? [UIColor colorWithHexString:paleRed] : [UIColor colorWithHexString:leafyGreen];
    }
    
}


-(instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor whiteColor];
        [self stockName];
        [self stockCode];
        
        [self nowPrice];
        
        [self price];

        
    }
    return self;
}

+(instancetype)buyStrategyTopViewWithStockDict:(NSDictionary *)dict
{
    YDBuyStrategyTopView *topView = [[self alloc] init];
    topView.dict = dict;
    return topView;
}

-(UILabel *)stockName
{
    if (_stockName == nil) {
        UILabel *stockName = [[UILabel alloc] init];
        [self addSubview:stockName];
        stockName.textAlignment = NSTextAlignmentLeft;
        stockName.textColor = [UIColor colorWithHexString:dark];
    
        stockName.font = [UIFont systemFontOfSize:font20ScreenWRate * LKScreenW];
        stockName.text = @"京东方a";
        [stockName mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self).offset(rate375(12));
            if (isPhoneX) {
                make.top.equalTo(self).offset(rateX812(14));
            }else{
                
                make.top.equalTo(self).offset(rate750(14));
            }
        }];
        _stockName = stockName;
    }
    return _stockName;
}
-(UILabel *)stockCode
{
    if (_stockCode == nil) {
        UILabel *stockCode = [[UILabel alloc] init];
        [self addSubview:stockCode];
        stockCode.textAlignment = NSTextAlignmentLeft;
        stockCode.textColor = [UIColor colorWithHexString:blueyGrey];
        stockCode.font = [UIFont systemFontOfSize:font12ScreenWRate * LKScreenW];
        stockCode.text = @"000725";
        [stockCode mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self).offset(rate375(12));
            if (isPhoneX) {
                make.bottom.equalTo(self).offset(-rateX812(14));
            }else{
                make.bottom.equalTo(self).offset(-rate750(14));
            }
        }];
        _stockCode = stockCode;
    }
    return _stockCode;
}
-(UILabel *)nowPrice
{
    if (_nowPrice == nil) {
        UILabel *nowPrice = [[UILabel alloc] init];
        [self addSubview:nowPrice];
        nowPrice.textAlignment = NSTextAlignmentLeft;
        nowPrice.textColor = [UIColor colorWithHexString:blueyGrey];
        nowPrice.font = [UIFont systemFontOfSize:font14ScreenWRate * LKScreenW];
        nowPrice.text = @"最新价：";
        [nowPrice mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(self);
            make.left.equalTo(self).offset(rate375(226));
            make.width.equalTo(@(rate375(56)));
            if (isPhoneX) {
                make.height.equalTo(@(rateX812(20)));
            }else{
                make.height.equalTo(@(rate750(20)));
            }
        }];
        nowPrice.adjustsFontSizeToFitWidth = YES;
        _nowPrice = nowPrice;
    }
    return _nowPrice;
}

-(UILabel *)price
{
    if (_price == nil) {
        UILabel *price = [[UILabel alloc] init];
        [self addSubview:price];
        price.textAlignment = NSTextAlignmentLeft;
        price.textColor = [UIColor colorWithHexString:paleRed];
        price.font = [UIFont boldSystemFontOfSize:font32ScreenWRate * LKScreenW];
        price.text = @"6.15";
        [price mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(self);
            make.left.equalTo(self.nowPrice.mas_right);
            make.right.equalTo(self).offset(-rate375(12));
        }];
        price.adjustsFontSizeToFitWidth = YES;
        _price = price;
    }
    return _price;
}

@end
